﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace intelliEssay.Graphics.Globalization
{
    public class ResourceDictionary
    {
        public Dictionary<string, string> resourceDictionary = new Dictionary<string, string>();
        object storage;

        public ResourceDictionary(object backendStorage)
        {
            storage = backendStorage;
        }

        public void Load()
        {
            var properties = storage.GetType().GetFields();
            foreach (var prop in properties)
            {
                resourceDictionary.Add(prop.Name.ToLowerInvariant(), prop.GetValue(storage).ToString());
            }
        }

        public string this[string propertyName]
        {
            get
            {
                try
                {
                    propertyName = propertyName.ToLowerInvariant();
                    return resourceDictionary[propertyName];
                }
                catch
                {
                    return string.Format("Losing {0} for culture {1}", propertyName, Shell.Environment.SettingFile.DisplayCulture);
                }
            }
        }
    }


}
